/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.model.relations;

import org.jfonia.connect5.intervals.Interval;
import org.jfonia.connect5.relations.MergeRelationLong;
import org.jfonia.model.PerformanceNode;
import org.jfonia.model.PerformanceSequence;
import org.jfonia.model.elements.MusicalElement;

/**
 *
 * @author Jannes Plyson
 */
public class MergePerformanceRelation extends MergeRelationLong{
    private MusicalElement musicalElement1;
    private MusicalElement musicalElement2;

    public MergePerformanceRelation(PerformanceNode perNode1, PerformanceNode perNode2, PerformanceSequence perSeq,MusicalElement musEl1,MusicalElement musEl2){
        super(perNode1,perNode2,perSeq);
        musicalElement1 = musEl1;
        musicalElement2 = musEl2;        
    }

    @Override
    protected void merge(Interval<Long> lastInterval){
        int diff = musicalElement1.getDifference() + musicalElement2.getDifference();
        super.merge(lastInterval);
        mergeDone = false;
        musicalElement2.setDifference(diff);
        musicalElement1.setDifference(diff);
        musicalElement1 = null; //make available for Garbage Collector
        musicalElement2 = null; //make available for Garbage Collector
        mergeDone = true;
    }
}
